package com.hxkcloud.patient.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.YjhApplication;
import com.hxkcloud.patient.activitys.EvaluateInfoActivity;
import com.hxkcloud.patient.activitys.MonitorInfoActivity;
import com.hxkcloud.patient.activitys.SystemInfoActivity;

/**
 * Created by william_sun on 2016-10-10.
 * Description:医生端-消息主页
 */
public class DoctorMessageFragment extends BaseFragment implements View.OnClickListener {
    private View view;

    //title
    private LinearLayout ll_title;
    private TextView tv_title;

    private LinearLayout ll_monitor;
    private ImageView iv_monitor;
    private ImageView iv_monitorp;
    private LinearLayout ll_assess;
    private ImageView iv_assess;
    private ImageView iv_assessp;
    private LinearLayout ll_system;
    private ImageView iv_system;
    private ImageView iv_systemp;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_doctormsg, container, false);
        initView();
        return view;
    }

    @Override
    protected void initView() {
        ll_title = (LinearLayout) view.findViewById(R.id.ll_title);
        tv_title = (TextView) view.findViewById(R.id.tv_title_title);

        ll_monitor = (LinearLayout) view.findViewById(R.id.ll_doctormsg_monitor);
        iv_monitor = (ImageView) view.findViewById(R.id.iv_doctormsg_monitor);
        iv_monitorp = (ImageView) view.findViewById(R.id.iv_doctormsg_monitorpoint);
        ll_assess = (LinearLayout) view.findViewById(R.id.ll_doctormsg_assess);
        iv_assess = (ImageView) view.findViewById(R.id.iv_doctormsg_assess);
        iv_assessp = (ImageView) view.findViewById(R.id.iv_doctormsg_assesspoint);
        ll_system = (LinearLayout) view.findViewById(R.id.ll_doctormsg_system);
        iv_system = (ImageView) view.findViewById(R.id.iv_doctormsg_system);
        iv_systemp = (ImageView) view.findViewById(R.id.iv_doctormsg_systempoint);

        setTitlePadding(ll_title);
        tv_title.setText(getResources().getText(R.string.message));

        RelativeLayout.LayoutParams lp_iv = new RelativeLayout.LayoutParams(screenWidth / 8, screenWidth / 8);
        iv_monitor.setLayoutParams(lp_iv);
        iv_assess.setLayoutParams(lp_iv);
        iv_system.setLayoutParams(lp_iv);

        ll_monitor.setOnClickListener(this);
        ll_assess.setOnClickListener(this);
        ll_system.setOnClickListener(this);

    }

    @Override
    public void onResume() {
        super.onResume();
        if (YjhApplication.msg_monitor) {
            iv_monitorp.setVisibility(View.VISIBLE);
        } else {
            iv_monitorp.setVisibility(View.INVISIBLE);
        }
        if (YjhApplication.msg_assessNurse) {
            iv_assessp.setVisibility(View.VISIBLE);
        } else {
            iv_assessp.setVisibility(View.INVISIBLE);
        }
        if (YjhApplication.msg_system) {
            iv_systemp.setVisibility(View.VISIBLE);
        } else {
            iv_systemp.setVisibility(View.INVISIBLE);
        }

        if (YjhApplication.msg_monitor || YjhApplication.msg_assessNurse || YjhApplication.msg_system) {
            YjhApplication.msg_new = true;
        } else {
            YjhApplication.msg_new = false;
        }
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void updateByHandler(Message msg) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_doctormsg_monitor:
                YjhApplication.msg_monitor = false;
                setMsg();
                Intent iM = new Intent(mContext, MonitorInfoActivity.class);
                startActivity(iM);
//                Intent iP = new Intent(mContext, DpatientInfoActivity.class);
//                iP.putExtra("patientid", "657");
//                iP.putExtra("name", "我的名字");
//                iP.putExtra("age", "12岁");
//                iP.putExtra("sex", "男");
//                startActivity(iP);
                break;
            case R.id.ll_doctormsg_assess:
                YjhApplication.msg_assessNurse = false;
                setMsg();
                Intent iA = new Intent(mContext, EvaluateInfoActivity.class);//消息，评估提醒(医护端)
                startActivity(iA);
                break;
            case R.id.ll_doctormsg_system:
                YjhApplication.msg_system = false;
                setMsg();
                Intent iS = new Intent(mContext, SystemInfoActivity.class);
                startActivity(iS);
                break;
        }
    }

    private void setMsg() {
        if (YjhApplication.msg_monitor || YjhApplication.msg_assessNurse || YjhApplication.msg_system) {
            YjhApplication.msg_new = true;
        } else {
            YjhApplication.msg_new = false;
        }
    }

    public void haveNewMsg() {
        if (YjhApplication.msg_monitor) {
            iv_monitorp.setVisibility(View.VISIBLE);
        } else {
            iv_monitorp.setVisibility(View.INVISIBLE);
        }
        if (YjhApplication.msg_assessNurse) {
            iv_assessp.setVisibility(View.VISIBLE);
        } else {
            iv_assessp.setVisibility(View.INVISIBLE);
        }
        if (YjhApplication.msg_system) {
            iv_systemp.setVisibility(View.VISIBLE);
        } else {
            iv_systemp.setVisibility(View.INVISIBLE);
        }

        if (YjhApplication.msg_monitor || YjhApplication.msg_assessNurse || YjhApplication.msg_system) {
            YjhApplication.msg_new = true;
        } else {
            YjhApplication.msg_new = false;
        }
    }
}
